package com.ambientrs.script.methods;

import com.ambientrs.bot.Boot;
import com.ambientrs.bot.io.Logger;

import javax.swing.text.BadLocationException;
import java.io.IOException;

public class Methods {

    private static Logger logger;

    /**
     * Appends the selected text to the log.
     *
     * @param text The text to append to the log.
     */
    public static void log(String text) {
        try {
            if (logger == null)
                logger = new Logger();
            logger.write(text);
            logger.newLine();
            logger.flush();
            Boot.gui.appendToLog('\n' + text, false);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BadLocationException e) {
            e.printStackTrace();
        }
    }

    /**
     * Generates a random integer between min and max (both inclusive).
     *
     * @param min The minimum possible number.
     * @param max The maximum possible number.
     * @return The random number.
     */
    public static int boundedRandom(int min, int max) {
        return Calculations.boundedRandom(min, max);
    }

    /**
     * Generates a random number a maximum of the specified distance from the
     * base.
     *
     * @param base    The number to randomize.
     * @param variant The maximum distance from the base.
     * @return The randomized base.
     */
    public static int random(int base, int variant) {
        return Calculations.boundedRandom(base, variant);
    }

}
